*&---------------------------------------------------------------------*
*& 包含               ZFIU026_CLS
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       CLASS lcl_events DEFINITION
*----------------------------------------------------------------------*
* SALV Event Handler Definition                                        *
*----------------------------------------------------------------------*
CLASS GCL_EVENTS_HANDLER DEFINITION.
  PUBLIC SECTION.
    METHODS:
      ON_LINK_CLICK FOR EVENT LINK_CLICK  "Hotspot Handler
        OF CL_SALV_EVENTS_TABLE
        IMPORTING ROW COLUMN,

      ON_LINK_CLICK_HIS FOR EVENT LINK_CLICK  "Hotspot Handler
        OF CL_SALV_EVENTS_TABLE
        IMPORTING ROW COLUMN,

      ON_USER_COMMAND FOR EVENT ADDED_FUNCTION OF CL_SALV_EVENTS
        IMPORTING E_SALV_FUNCTION.
ENDCLASS.                    "lcl_events DEFINITION
*
*----------------------------------------------------------------------*
*       CLASS lcl_events IMPLEMENTATION
*----------------------------------------------------------------------*
*  SAL Event Handler Methods                                           *
*----------------------------------------------------------------------*
CLASS GCL_EVENTS_HANDLER IMPLEMENTATION.
  METHOD ON_LINK_CLICK.
    DATA:
      LV_TCODE      TYPE SY-TCODE,
      LS_PARAMETER  TYPE /PTGWFI/PIDVAL,
      LT_PARAMETERS TYPE TABLE OF /PTGWFI/PIDVAL,
      LV_MSG1(80)   TYPE C,
      LV_MSG2(80)   TYPE C.

    DATA: LV_OBJ TYPE SMENSAPNEW-REPORT,
          LV_REP TYPE SMENSAPNEW-REPORTTYPE,
          LV_URL TYPE SMEN_BUFFI-URL.

    READ TABLE GT_RESULT INTO DATA(LS_RESULT) INDEX ROW.
    IF SY-SUBRC = 0.
      CASE COLUMN.
        WHEN 'PDF_URL'.
          IF LS_RESULT-PDF_URL IS NOT INITIAL.
            LV_OBJ = 'URL'.
            LV_REP = 'OT'.
            LV_URL = LS_RESULT-PDF_URL.

            CALL FUNCTION 'MENU_START_OBJECT_VIA_INDX'
              EXPORTING
                OBJECT_NAME = LV_OBJ
                REPORTTYPE  = LV_REP
                URL         = LV_URL.
          ENDIF.

        WHEN 'XML_URL'.
          IF LS_RESULT-XML_URL IS NOT INITIAL.
            LV_OBJ = 'URL'.
            LV_REP = 'OT'.
            LV_URL = LS_RESULT-XML_URL.

            CALL FUNCTION 'MENU_START_OBJECT_VIA_INDX'
              EXPORTING
                OBJECT_NAME = LV_OBJ
                REPORTTYPE  = LV_REP
                URL         = LV_URL.
          ENDIF.

        WHEN 'JSDDH'.
          IF LS_RESULT-JSDDH IS NOT INITIAL.
            SET PARAMETER ID 'ZJSDDH' FIELD LS_RESULT-JSDDH.
            CALL TRANSACTION 'ZFIU019_01' AND SKIP FIRST SCREEN.
          ENDIF.

        WHEN 'DOCID'.

          IF LS_RESULT-DOCID IS NOT INITIAL.
            CALL FUNCTION '/OPT/VIM_DISPLAY_DOCUMENT'
              EXPORTING
                DOCID                 = LS_RESULT-DOCID
                POPUP                 = 'X'
              EXCEPTIONS
                INVALID_DOCUMENT      = 1
                SYSTEM_FAILURE        = 2 MESSAGE LV_MSG2
                COMMUNICATION_FAILURE = 3
                OTHERS                = 4.
            IF SY-SUBRC EQ 1.
              MESSAGE I075(/OPT/VIM_M_CLASS).
            ELSEIF SY-SUBRC EQ 2 OR
                   SY-SUBRC EQ 3.
              MESSAGE LV_MSG2 TYPE 'S' DISPLAY LIKE 'E'.

            ELSEIF SY-SUBRC NE 0.
              MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
            ENDIF.
          ENDIF.

        WHEN 'BELNR'.

          CHECK NOT LS_RESULT-BELNR IS INITIAL.
          SET PARAMETER ID 'BLN' FIELD LS_RESULT-BELNR.
          SET PARAMETER ID 'GJR' FIELD LS_RESULT-GJAHR.
          SET PARAMETER ID 'BUK' FIELD LS_RESULT-BUKRS.
          CALL FUNCTION 'AUTHORITY_CHECK_TCODE'             "2334943
            EXPORTING
              TCODE  = 'FB03'
            EXCEPTIONS
              OK     = 1
              NOT_OK = 2
              OTHERS = 3.

          IF SY-SUBRC <> 1.
            MESSAGE E172(00) WITH 'FB03'.
          ELSE.
            CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
          ENDIF.

        WHEN OTHERS.
      ENDCASE.
    ENDIF.

  ENDMETHOD.

  METHOD ON_LINK_CLICK_HIS.
    DATA:
      LV_TCODE      TYPE SY-TCODE,
      LS_PARAMETER  TYPE /PTGWFI/PIDVAL,
      LT_PARAMETERS TYPE TABLE OF /PTGWFI/PIDVAL,
      LV_MSG1(80)   TYPE C,
      LV_MSG2(80)   TYPE C.

    READ TABLE GT_HISTORY INTO DATA(LS_HISTORY) INDEX ROW.
    IF SY-SUBRC = 0.
      CASE COLUMN.
        WHEN 'JSDDH'.
          SET PARAMETER ID 'ZJSDDH' FIELD LS_HISTORY-JSDDH.
          CALL TRANSACTION 'ZFIU019_01' AND SKIP FIRST SCREEN.

        WHEN 'DOCID'.

          IF LS_HISTORY-DOCID IS NOT INITIAL.
            CALL FUNCTION '/OPT/VIM_DISPLAY_DOCUMENT'
              EXPORTING
                DOCID                 = LS_HISTORY-DOCID
              " POPUP                 = SPACE
              EXCEPTIONS
                INVALID_DOCUMENT      = 1
                SYSTEM_FAILURE        = 2 MESSAGE LV_MSG2
                COMMUNICATION_FAILURE = 3
                OTHERS                = 4.
            IF SY-SUBRC EQ 1.
              MESSAGE I075(/OPT/VIM_M_CLASS).
            ELSEIF SY-SUBRC EQ 2 OR
                   SY-SUBRC EQ 3.
              MESSAGE LV_MSG2 TYPE 'S' DISPLAY LIKE 'E'.

            ELSEIF SY-SUBRC NE 0.
              MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
            ENDIF.
          ENDIF.

        WHEN 'BELNR'.

          CHECK NOT LS_HISTORY-BELNR IS INITIAL.
          SET PARAMETER ID 'BLN' FIELD LS_HISTORY-BELNR.
          SET PARAMETER ID 'GJR' FIELD LS_HISTORY-GJAHR.
          SET PARAMETER ID 'BUK' FIELD LS_HISTORY-BUKRS.
          CALL FUNCTION 'AUTHORITY_CHECK_TCODE'             "2334943
            EXPORTING
              TCODE  = 'FB03'
            EXCEPTIONS
              OK     = 1
              NOT_OK = 2
              OTHERS = 3.

          IF SY-SUBRC <> 1.
            MESSAGE E172(00) WITH 'FB03'.
          ELSE.
            CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
          ENDIF.

        WHEN OTHERS.
      ENDCASE.
    ENDIF.

  ENDMETHOD.

  METHOD ON_USER_COMMAND.

    DATA:
      LV_INVDEL_FLG TYPE C,
      LR_COLUMNS    TYPE REF TO CL_SALV_COLUMNS_TABLE,
      LV_ROW_COUNT  TYPE I,
      LS_RESULT     TYPE TY_RESULT,
      LT_SELECT_D   TYPE STANDARD TABLE OF TY_RESULT,
      LT_SELECT_ROW TYPE SALV_T_ROW,
      LS_SELECT_ROW TYPE I,
      LR_SELECTS    TYPE REF TO CL_SALV_SELECTIONS.


    CASE E_SALV_FUNCTION.
      WHEN '&ZDEVINV'.
        AUTHORITY-CHECK OBJECT 'ZFI_DELINV'
         ID 'ACTVT' DUMMY.
        IF SY-SUBRC <> 0.
          MESSAGE '您无权限使用该功能'(M05) TYPE 'S' DISPLAY LIKE 'E'.
          LEAVE LIST-PROCESSING.
        ELSE.

          LR_SELECTS = GR_TABLE->GET_SELECTIONS( ).
          LT_SELECT_ROW = LR_SELECTS->GET_SELECTED_ROWS( ).
          LV_ROW_COUNT = LINES( LT_SELECT_ROW ).

          IF LV_ROW_COUNT = 0.
            MESSAGE '请至少选择一条记录'(M06) TYPE 'S' DISPLAY LIKE 'E'.
            LEAVE LIST-PROCESSING.
          ELSE.

            CLEAR LV_INVDEL_FLG.
            LOOP AT LT_SELECT_ROW INTO LS_SELECT_ROW.

              CLEAR LS_RESULT.
              READ TABLE GT_RESULT INTO LS_RESULT INDEX LS_SELECT_ROW.
              IF LS_RESULT-ZFPZT = '10' AND LS_RESULT-ZFPLX = '国内'.

                LV_INVDEL_FLG = 'X'.

                DELETE GT_RESULT INDEX SY-TABIX.

                DELETE FROM ZFIT078_HEAD WHERE ZFPHM = LS_RESULT-ZFPHM.
                DELETE FROM ZFIT078_HIS WHERE ZFPHM = LS_RESULT-ZFPHM.
              ENDIF.
            ENDLOOP.

            IF LV_INVDEL_FLG IS NOT INITIAL.

              MESSAGE '已接收状态的原始发票已删除'(M08) TYPE 'I'.
              PERFORM FRM_GET_DATA.

              LR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
              LR_COLUMNS->SET_OPTIMIZE( 'X' ).
              GR_TABLE->REFRESH( ).
            ELSE.

              MESSAGE '无原始发票可删除'(M07) TYPE 'S'.
            ENDIF.
          ENDIF.

        ENDIF.

      WHEN '&ZREFRESH'.
        PERFORM FRM_GET_DATA.

        LR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
        LR_COLUMNS->SET_OPTIMIZE( 'X' ).
        GR_TABLE->REFRESH( ).

      WHEN '&ZHIS'.
        LR_SELECTS = GR_TABLE->GET_SELECTIONS( ).
        LT_SELECT_ROW = LR_SELECTS->GET_SELECTED_ROWS( ).
        LV_ROW_COUNT = LINES( LT_SELECT_ROW ).

        IF LV_ROW_COUNT <> 1.
          MESSAGE '请选择一条数据，且只能选择一条'(M02) TYPE 'S' DISPLAY LIKE 'E'.
          LEAVE LIST-PROCESSING.
        ELSE.

          LOOP AT LT_SELECT_ROW INTO LS_SELECT_ROW.

            CLEAR LS_RESULT.
            READ TABLE GT_RESULT INTO LS_RESULT INDEX LS_SELECT_ROW.
            IF SY-SUBRC = 0.
              PERFORM FRM_DIS_HISTORY USING LS_RESULT.
            ENDIF.
            EXIT.
          ENDLOOP.

        ENDIF.
      WHEN OTHERS.
    ENDCASE.
  ENDMETHOD.
  "on_link_click
ENDCLASS.                    "lcl_events IMPLEMENTATION

DATA: GR_EVENTS_HANDLER TYPE REF TO GCL_EVENTS_HANDLER.
